package com.lvhx.springboot.springbatch.readfile;

import com.lvhx.springboot.entity.User;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.validation.BindException;

/**
 * @auther 吕宏旭
 * @date 2019/9/4 15:26
 */
public class ReadFileMapper implements FieldSetMapper<User> {
    @Override
    public User mapFieldSet(FieldSet fieldSet) throws BindException {
        User user = new User();
        user.setId(Long.valueOf(fieldSet.readString(0)));
        user.setName(fieldSet.readString(1));
        user.setPassword(fieldSet.readString(2));
//        user.setVersion(1L);
        return user;
    }
}
